package com.lingchou.cloud.process.api.controller;

import com.lc.common.bean.response.Result;
import com.lingchou.cloud.process.api.dto.param.base.ProcessConfigVo;
import com.lingchou.cloud.process.api.dto.param.base.ProcessStartParamVo;
import com.lingchou.cloud.process.api.dto.result.ProcessInstanceDTO;
import com.lingchou.cloud.process.api.dto.result.base.NodeParamVo;
import com.lingchou.cloud.process.api.dto.result.base.ProcessConfigResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程基础版本API
 *
 * @author lc
 */
@RequestMapping(value = "process/base")
@Api(value = "ProcessBaseApi", tags = "简单流程基础版本API")
@Validated
public interface ProcessBaseApi {

    /**
     * 流程配置
     *
     * @return 流程配置
     */
    @ApiOperation(value = "流程配置", notes = "流程配置，默认每个task都是多实例，都有触发时的监听和边界时间时间")
    @PostMapping("/deploy")
    Result<ProcessConfigResultVo> deploy(@Validated @RequestBody ProcessConfigVo processConfigVo);

    /**
     * 流程配置查询
     *
     * @param businessKey 业务Key
     * @param startNum    开始数
     * @param rows        读取数
     * @return 流程配置列表
     */
    @ApiOperation(value = "配置查询", notes = "配置查询")
    @GetMapping("/deployments")
    Result<List<ProcessConfigResultVo>> deployments(@ApiParam(name = "businessKey", value = "业务Key") @RequestParam(required = false) String businessKey,
                                                    @ApiParam(name = "startNum", value = "开始数") @RequestParam(required = false) Integer startNum,
                                                    @ApiParam(name = "rows", value = "读取数") @RequestParam(required = false) Integer rows);

    /**
     * 删除流程配置
     *
     * @param deploymentId 部署ID
     * @return 流程配置列表
     */
    @ApiOperation(value = "流程配置删除", notes = "流程配置删除，")
    @DeleteMapping("/deleteDeployment")
    Result<Object> deleteDeployment(@ApiParam(name = "deploymentId", value = "业务Key") @RequestParam(required = false) String deploymentId);

    /**
     * 获取流程配置内的节点
     *
     * @param deploymentId 部署ID
     * @return 流程配置节点与变量参数
     */
    @ApiOperation(value = "获取流程配置内的节点", notes = "获取流程配置内的节点，包含节点变量：选人范围；节点类型（串签、或签、并签）；人员集合；截止时间；")
    @GetMapping("/getNodeParams")
    Result<List<NodeParamVo>> getNodeParams(@ApiParam(name = "deploymentId", value = "流程发布ID") @RequestParam(required = false) String deploymentId);

    /**
     * 创建新流程实例
     *
     * @return 流程实例ID
     */
    @ApiOperation(value = "启动流程", notes = "根据发布ID启动一个实例，可以指定业务key，返回实例ID")
    @PostMapping("/start")
    Result<ProcessInstanceDTO> startInstanceByDeployment(@Validated @RequestBody ProcessStartParamVo processStartParamVo);

    /**
     * 撤回流程
     *
     * @param processInstanceId 流程实例ID
     * @param operator          操作人
     */
    @GetMapping(value = "/revoke")
    @ApiOperation(value = "撤回流程", notes = "撤回指定ID流程")
    Result<String> revokeProcess(@ApiParam(name = "processInstanceId", value = "流程实例ID") @RequestParam String processInstanceId,
                                 @ApiParam(name = "operator", value = "操作人") @RequestParam String operator);
}
